#!/usr/bin/env python
# -*— coding: utf-8 -*-
from multiprocessing import Process, Queue
import os, time, random

# 写数据进程执行的代码
def write(q):
  for value in ['a', 'b', 'c']:
    q.put(value)
    time.sleep(random.random())

# 读数据进程执行的代码
def read(q):
  while True:
    if not q.empty():
      value = q.get(True)
      print('Get $s from queue.'%value)
      time.sleep(random.random()) 
    else:
      break

if __name__ == '__main__':
  q = Queue()

  pw = Process(target=write, args=(q,))
  pw.start()
  pw.join()

  pr = Process(target=read, args=(q,))
  pr.start()
  pr.join()

  print('所有数据写入完成')


